//
//  DetailforArtistVC.m
//  XDCommonApp
//
//  Created by xindaoapp on 14-3-10.
//  Copyright (c) 2014年 XD-XY. All rights reserved.
//

#import "DetailforArtistVC.h"
#import "XDTools.h"
#import "XDHeader.h"
#import "WaterDetailViewController.h"
#import "UIImageView+WebCache.h"
#import "LoginViewController.h"
#import "DetailOrgnizerCell.h"
#import "detailArtistCell.h"

#define dHeightForHeader 0.0

@interface DetailforArtistVC ()

{
    BOOL isFav;
    BOOL firstFav;
    NSString *artistIntroduction;//
    NSString *artistEducation;
    NSString *artistName;// 艺术家名字
    NSString *artistPortal;// 头像
    NSString *artistScanCount;
    NSString *artistStoreCount;
    NSString *artistWorkCount;// 作品量
    
    UIImageView * scanIV;
    
    UIView * lineView;
    UIView *hlineView;
    UIImageView * favIV;
    UIView * hlineView2;
    UIView * lineView2;

    UILabel *contLabel;
    UIImageView *arrowIV;
    float varHeight;
    BOOL isClicked;
    
}

@end

@implementation DetailforArtistVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
   
    
	// Do any additional setup after loading the view.
     isClicked = NO;

    [self isFavorite];
    
    [self initWidget];

    if ([_typeStr isEqualToString:@"2"]) {
        [self GETGALXMLData];
    }else{
        
        [self getXmlData];
    }
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    
    
}
- (void)initWidget
{
//    self.titleLabel.text = @"活动详情";
    self.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    self.titleLabel.textColor = TEXTBLACKCOLORE;
    
    [self.rightBtn setBackgroundImage:[UIImage imageNamed:@"nn"] forState:UIControlStateNormal];

    
    self.detailActTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, UI_SCREEN_WIDTH,self.contentView.frame.size.height) style:UITableViewStylePlain];
    _detailActTableView.delegate = self;
    _detailActTableView.dataSource = self;
    _detailActTableView.backgroundColor = [UIColor clearColor];
    
    [self.contentView addSubview:_detailActTableView];
    
    self.shareView = [[XDShareView alloc] initWithFrame:CGRectMake(0, UI_STATUS_BAR_HEIGHT, UI_SCREEN_WIDTH, UI_SCREEN_HEIGHT)];
    _shareView.delegate = self;
    _shareView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_shareView];
    _shareView.hidden =YES;
}

-(void)sharebtnClick
{
    _shareView.hidden =NO;   
}

#pragma mark ================XDShareView Delegate===============
-(void)shareViewBtnCLick:(UIButton *)button
{
    int tag = button.tag - SHAREBTNTAG;
    //设置分享内容和回调对象
    if (tag == 0){
        //微信会话
        [UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeText;
        [[UMSocialControllerService defaultControllerService] setShareText:@"分享到微信－找画APP" shareImage:[UIImage imageNamed:@"Icon"] socialUIDelegate:self];
        [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
    }else if (tag == 1){
        //朋友圈分享
        [[UMSocialControllerService defaultControllerService] setShareText:@"分享到朋友圈－找画APP" shareImage:[UIImage imageNamed:@"Icon"] socialUIDelegate:self];
        [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatTimeline].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
    }else if (tag == 2){
        //新浪微博
        [[UMSocialControllerService defaultControllerService] setShareText:@"分享到新浪微博－找画APP" shareImage:[UIImage imageNamed:@"Icon"] socialUIDelegate:self];
        [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
    }else if (tag == 3){
        //复制链接地址
        [[UIPasteboard generalPasteboard] setString:[NSString stringWithFormat:@"%@%@",ImageMainUrl,artistPortal]];
        [XDTools showTips:@"复制成功" toView:_shareView];
    }else if (tag == 4){
        //关闭
        _shareView.hidden =YES;
    }
}


#pragma mark  --------------tableView delegate----------------

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //    if (section == 0||section==1){
    //        return 1;
    //    }
    return 1;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 3;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==0) {
        return 0;
    }
//    if (section==1) {
//        return 40;
//
//    }else{
//        return 0;
//    }
    

    return dHeightForHeader;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    NSArray * array;
    CGFloat headerHeight=0;
    if (tableView == _detailActTableView){
        
        array=@[@"0",@"活动介绍",@"参展机构"];
        headerHeight = dHeightForHeader;
    }
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, headerHeight)];
    view.backgroundColor = RGBA(217, 217, 217, 1);
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, UI_SCREEN_WIDTH-15, headerHeight)];
    label.textColor = TEXTBLACKCOLORE;
    label.font = [UIFont systemFontOfSize:15];
    label.backgroundColor = [UIColor clearColor];
    label.text = [array objectAtIndex:section];
    [view addSubview:label];
    return view;
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    if (indexPath.section == 0){
        return 176;
    }else if(indexPath.section==1){
//        return 100;
        if (artistIntroduction.length <1) {
            arrowIV.hidden = YES;
            return 0;
        }else{
            arrowIV.hidden = NO;
        }
        if (!isClicked) {

            return 110;
        }else{
            return contLabel.frame.size.height + 40;
        }
        //        return 20/2.0f+82/2.0f;
        DDLOG(@"is varHeight = %f",varHeight);

        return varHeight;

    }else {
        
        return 60.0f;
        
    }
}


-(UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

        if (indexPath.section == 0) {

            static NSString * cellName = @"cell";
            UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellName];
            if (cell == nil){
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
                cell.backgroundColor = [UIColor clearColor];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }

            if (!artImgV) {
                artImgV = [[UIImageView alloc]initWithFrame:CGRectMake(15, 15, 106, 106)];
                //            artImgV.backgroundColor = [UIColor clearColor];
                artImgV.backgroundColor = UIColorFromRGB(0xdbdada);

                NSString * imageUrl = [NSString stringWithFormat:@"%@%@",ImageMainUrl,artistPortal];
                NSString * urlstring = [imageUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                //            artImgV.tag = 200;
                DDLOG(@"url = %@",urlstring);

                [artImgV setImageWithURL:[NSURL URLWithString:urlstring] placeholderImage:[UIImage imageNamed:@"placehold_image"]];

                [cell.contentView addSubview:artImgV];
            }

            
            UIFont *artFont = [UIFont boldSystemFontOfSize:20];
            if (!artNameLb) {
                artNameLb = [[UILabel alloc]init];
                artNameLb.frame = CGRectMake(width_x(artImgV)+10, artImgV.frame.origin.y+10,160, 0);
                artNameLb.font = artFont;
                artNameLb.numberOfLines = 0;
                artNameLb.backgroundColor = [UIColor clearColor];
                CGSize size = CGSizeMake(300, 200.0f);
                //            if (artistName==nil||[artistName isEqualToString:@""]) {
                //                artistName = @"史密斯";
                //            }
                NSString *str = @"史密斯";
                size = [str sizeWithFont:artFont constrainedToSize:CGSizeMake(artNameLb.frame.size.width, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
                //根据计算结果重新设置label的尺寸
                [artNameLb setFrame:CGRectMake(width_x(artImgV)+10, artImgV.frame.origin.y+10, 200, size.height)];
                artNameLb.text = str;
                [cell.contentView addSubview:artNameLb];
            }

            if (!profileLabel) {
                profileLabel = [[UILabel alloc]initWithFrame:CGRectMake(artNameLb.frame.origin.x, height_y(artNameLb), 160, 30)];
                profileLabel.backgroundColor = [UIColor clearColor];
                profileLabel.numberOfLines = 0;
                profileLabel.textColor = TEXTBLACKCOLORE4;
                profileLabel.font = [UIFont systemFontOfSize:13];

                CGSize Psize = CGSizeMake(140, 2000.0f);
                NSString *Pstr = @"1954年生于德国纽伦堡\n1970年6月至1974年6月就读于\n纽伦堡大学美术学院";
                Psize = [Pstr sizeWithFont:profileLabel.font constrainedToSize:CGSizeMake(profileLabel.frame.size.width, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];

                NSAttributedString *attributedString =[[NSAttributedString alloc] initWithString:Pstr attributes:@{NSKernAttributeName : @(5.0f)}];
                [profileLabel setAttributedText:attributedString];
                profileLabel.text = Pstr;
                //根据计算结果重新设置label的尺寸
                [profileLabel setFrame:CGRectMake(artNameLb.frame.origin.x, height_y(artNameLb), 160, Psize.height)];
                [cell.contentView addSubview:profileLabel];
                

            }

            if (!favBtn) {
                lineView = [[UIView alloc] initWithFrame:CGRectMake(0, height_y(artImgV)+10, UI_SCREEN_WIDTH, 1)];
                lineView.backgroundColor = RGBA(219, 219, 219, 1);
                [cell.contentView addSubview:lineView];

                favBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                favBtn.frame = CGRectMake(0, height_y(lineView), UI_SCREEN_WIDTH/2-2, 44);
                favBtn.backgroundColor = [UIColor clearColor];
                [cell.contentView addSubview:favBtn];

                hlineView = [[UIView alloc]initWithFrame:CGRectMake(width_x(favBtn), height_y(lineView)+5, 1, 34)];
                hlineView.backgroundColor = RGBA(219, 219, 219, 1);
                [cell.contentView addSubview:hlineView];

                scaneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                scaneBtn.frame = CGRectMake(width_x(hlineView), height_y(lineView), UI_SCREEN_WIDTH/2-2, 44);
                scaneBtn.backgroundColor = [UIColor clearColor];
                [cell.contentView addSubview:scaneBtn];

                scanIV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"artist_Fav"]];
                scanIV.frame = CGRectMake(UI_SCREEN_WIDTH/4-8, 5, 16, 16);

                scanLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 22, UI_SCREEN_WIDTH/2, 22)];
                scanLabel.backgroundColor = [UIColor clearColor];
                scanLabel.textColor  = TEXTBLACKCOLORE3;
                scanLabel.font = [UIFont systemFontOfSize:11];

                scanLabel.textAlignment = NSTextAlignmentCenter;
                [favBtn addSubview:scanLabel];
                [favBtn addSubview:scanIV];

                //            if ([_typeStr intValue]==0) {

                scanLabel.text=@"10次关注";//[NSString stringWithFormat:@"%@次关注",artistStoreCount];
                [favBtn addTarget:self action:@selector(favBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
                //            }else{
                //                scanLabel.text = [NSString stringWithFormat:@"%@次浏览",artistScanCount];
                //            }
                UIImageView *shareIV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"share_icon"]];
                shareIV.frame = CGRectMake(UI_SCREEN_WIDTH/4-9, 7, 18, 16);

                UILabel *shareLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 22, UI_SCREEN_WIDTH/2, 22)];
                shareLabel.backgroundColor = [UIColor clearColor];
                shareLabel.textColor  = TEXTBLACKCOLORE3;
                shareLabel.font = [UIFont systemFontOfSize:11];
                shareLabel.text = [NSString stringWithFormat:@"分享"];
                shareLabel.textAlignment = NSTextAlignmentCenter;

                [scaneBtn addSubview:shareIV];
                [scaneBtn addSubview:shareLabel];
                [scaneBtn addTarget:self action:@selector(sharebtnClick) forControlEvents:UIControlEventTouchUpInside];

                lineView2 = [[UIView alloc] initWithFrame:CGRectMake(0, height_y(favBtn), UI_SCREEN_WIDTH, 1)];
                lineView2.backgroundColor = RGBA(219, 219, 219, 1);
                [cell.contentView addSubview:lineView2];
            }

            return cell;
            
        }else if (indexPath.section==1&&indexPath.row==0){
            //活动介绍
            static NSString * cellName1 = @"cell1";
            UITableViewCell * cell1 = [tableView dequeueReusableCellWithIdentifier:cellName1];
            if (cell1 == nil){
                cell1 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName1];
                //                cell1.backgroundColor = UIColorFromRGB(0xdbdada);
                cell1.selectionStyle = UITableViewCellSelectionStyleNone;
                //            cell.backgroundColor = UIColorFromRGB(0xdbdada);
                cell1.backgroundColor = [UIColor clearColor];
            }
//            if (contLabel) {
            if (contLabel==nil) {
//
                contLabel = [[UILabel alloc ]init];
                contLabel.backgroundColor = [UIColor clearColor];
                contLabel.font = [UIFont systemFontOfSize:13];
                contLabel.frame = CGRectMake(15, 5, 290, 80);
                contLabel.text = artistIntroduction;
                DDLOG(@"intro cell \n\n\n\n = %@",artistIntroduction);

                contLabel.numberOfLines = 4;
                contLabel.lineBreakMode = NSLineBreakByTruncatingTail;

                arrowIV = [[UIImageView alloc ]init];
                arrowIV.backgroundColor = [UIColor clearColor];
                arrowIV.frame = CGRectMake(150, height_y(contLabel), 10, 10);
                arrowIV.image = [UIImage imageNamed:@"shaixuan_down"];

                [cell1.contentView  addSubview:contLabel];
            }else{
                [cell1.contentView addSubview:contLabel];
            }
            DDLOG(@"cell1 = %@",cell1.contentView.subviews);



                [cell1.contentView addSubview:arrowIV];
//            }
            return cell1;

            
        }else if (indexPath.section == 2){

            static NSString * cellName2 = @"cell2";
            DetailOrgnizerCell * cell2 = [tableView dequeueReusableCellWithIdentifier:cellName2];
            if (cell2 == nil){
                cell2 = [[DetailOrgnizerCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName2];
                cell2.backgroundColor = [UIColor clearColor];
                cell2.selectionStyle = UITableViewCellSelectionStyleNone;
            }

            if(artistWorkCount==nil){
                artistWorkCount = @"0";
            }
            cell2.ognizerLabel.text = [NSString stringWithFormat:@"作品  (%@)",artistWorkCount];//@"作品(24)";
            cell2.ognizerLabel.font = [UIFont systemFontOfSize:17];
//            UIImageView *nextLvIV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"launh_sure"]];
//            cell2.frame = CGRectMake(290, 20, 13, 18);
//            cell2.backgroundColor = [UIColor clearColor];
//            [cell2.contentView addSubview:nextLvIV];

            return cell2;
        }

    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    if (indexPath.section == 1) {
        
//        NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:13],NSFontAttributeName,nil];
//        CGSize  actualsize =[artistIntroduction boundingRectWithSize:CGSizeMake(290, 800) options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;
//
//        isClicked = !isClicked;
//
//        if (isClicked) {
//
//            varHeight = actualsize.height+20;
//
//            contLabel.frame = [XDTools xyAutoSizeOfWidget:contLabel andSize:CGSizeMake(290, 800) andtextFont:13];
//            contLabel.numberOfLines = 0;
//            contLabel.text = artistIntroduction;
//            DDLOG(@"didselect = %@",artistIntroduction);
//
//            arrowIV.frame = CGRectMake(150, height_y(contLabel), 10, 10);
//            arrowIV.image = [UIImage imageNamed:@"shaixuan_up"];
//
//        }else{
//
//
//            contLabel.frame = CGRectMake(15, 5, 290, 80);
////            contLabel.backgroundColor = [UIColor redColor];
//            contLabel.numberOfLines = 4;
//            arrowIV.frame = CGRectMake(150, height_y(contLabel), 10, 10);
//            contLabel.text = artistIntroduction;
//
//            arrowIV.image = [UIImage imageNamed:@"shaixuan_down"];
//        }
        
        isClicked = !isClicked;
        
        if (isClicked) {
            
            varHeight = contLabel.frame.size.height+20;
            
            contLabel.frame = [XDTools xyAutoSizeOfWidget:contLabel andSize:CGSizeMake(290, 800) andtextFont:13];
            contLabel.numberOfLines = 0;
            contLabel.text = artistIntroduction;
            DDLOG(@"didselect = %@",artistIntroduction);
            
            arrowIV.frame = CGRectMake(150, height_y(contLabel)+10, 10, 10);
            arrowIV.image = [UIImage imageNamed:@"shaixuan_up"];
            
        
            
        }else{
            
            
            contLabel.frame = CGRectMake(15, 5, 290, 80);
            //            contLabel.backgroundColor = [UIColor redColor];
            contLabel.numberOfLines = 4;
            arrowIV.frame = CGRectMake(150, height_y(contLabel), 10, 10);
            contLabel.text = artistIntroduction;
            
            arrowIV.image = [UIImage imageNamed:@"shaixuan_down"];
        }


        [tableView reloadData];
        // section
//             NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:1];
//         [tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
//        //        cell
//
//         NSIndexPath *indexPath=[NSIndexPath indexPathForRow:0 inSection:1];
//         [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];

        NSLog(@"size.height = %f",varHeight);
//        NSLog(@" cmmmmm = %@",activityIntroduce);

    }

    if(indexPath.section == 2){
        WaterDetailViewController *waterVC = [[WaterDetailViewController alloc] init];
        if ([_typeStr intValue] == 1) {
            waterVC.artistId = _idStr;
            waterVC.artistName = artistName;
            waterVC.signal = @"1";
        }else{
            waterVC.galleryId = _idStr;
            waterVC.signal = @"2";
        }
        

        [self.navigationController pushViewController:waterVC animated:YES];
        DDLOG(@"跳转到瀑布流");
    }
}

- (void)favBtnClicked:(id)sender
{
    DDLOG(@"关注按钮点击");
    firstFav  = NO;
    NSUserDefaults *Defaults = [NSUserDefaults standardUserDefaults];
    UID_STR = [NSString stringWithFormat:@"%@",[Defaults valueForKey:kMY_USER_ID]];
    
    if (UID_STR == nil||[UID_STR isEqualToString:@""]||[UID_STR isKindOfClass:[NSNull class]]||[UID_STR isEqualToString:@"(null)"]){
        LoginViewController * loginView = [[LoginViewController alloc] init];
        [self.navigationController pushViewController:loginView animated:YES];
        //        [self confirmSelectTabBar:_beforeIndex];
    }else{
//        [self isFavorite];
//
        if (isFav) {
            scanIV.image = [UIImage imageNamed:@"artist_NFav"];
            [self cancelFavorite];//取消
        }else{
            scanIV.image = [UIImage imageNamed:@"artist_Fav"];
            [self addFavorite];// 添加
        }
        
         isFav = !isFav;

    }
    
    
}


#pragma mark  -------- DataSouceManager------------

//、、判断
- (void)isFavorite{
    
    UID_STR = [[NSUserDefaults standardUserDefaults] valueForKey:kMY_USER_ID];
    
    DDLOG(@"workID = %@  uid = %@ ",self.idStr,UID_STR);
    
    if ([XDTools NetworkReachable]){
        NSString *body = [NSString stringWithFormat:@" <GetMyStoreInfor xmlns=\"http://tempuri.org/\">"
                          "<id>%@</id>"
                          "<uid>%@</uid>"
                          "<type>%@</type>"
                          "</GetMyStoreInfor>",self.idStr,UID_STR,_typeStr];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:GetMyStoreInfor];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            //[XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            // NSDictionary *tempDic = [XDTools  JSonFromString:responseString];
            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    DDLOG(@"res = %@",responseDict);
                    
                    isFav = [[NSString stringWithFormat:@"%@",[responseDict valueForKey:@"hasStore"]]boolValue];
                    DDLOG(@"ISFAV = %d",isFav);
                    
                        
                        if (isFav) {
                            scanIV.image = [UIImage imageNamed:@"artist_Fav"];
                            
                        }else{
                            scanIV.image = [UIImage imageNamed:@"artist_NFav"];
                            
                        }
                   
                }
            }
        }];
        
        [request setFailedBlock:^{
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }
    
    
}
// 添加

- (void)addFavorite{
    
    if ([XDTools NetworkReachable]){
        NSString *body = [NSString stringWithFormat:@" <AddStore xmlns=\"http://tempuri.org/\">"
                          "<id>%@</id>"
                          "<uid>%@</uid>"
                          "<type>%@</type>"
                          "</AddStore>",self.idStr,UID_STR,_typeStr];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:addStore];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            //[XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            // NSDictionary *tempDic = [XDTools  JSonFromString:responseString];
            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    DDLOG(@"res = %@",responseDict);
                    
                    artistStoreCount = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"totalStore"]];
                    if ([artistStoreCount isKindOfClass:[NSNull class]]&&[artistStoreCount isEqualToString:@"<null>"]) {
                        artistStoreCount = @"0";
                    }
//                    favLabel.text = [NSString stringWithFormat:@"%@次关注",artistStoreCount];
                    scanLabel.text=[NSString stringWithFormat:@"%@次关注",artistStoreCount];
                    
                    [XDTools showTips:@"添加关注成功" toView:self.contentView];
                }else{
                    [XDTools showTips:@"添加关注失败" toView:self.contentView];
                }
            }
        }];
        
        [request setFailedBlock:^{
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }
    
}
// 取消
- (void)cancelFavorite
{
    if ([XDTools NetworkReachable]){
        NSString *body = [NSString stringWithFormat:@" <CancelStore xmlns=\"http://tempuri.org/\">"
                          "<id>%@</id>"
                          "<uid>%@</uid>"
                          "<type>%@</type>"
                          "</CancelStore>",self.idStr,UID_STR,_typeStr];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:cancelStore];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            //[XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            // NSDictionary *tempDic = [XDTools  JSonFromString:responseString];
            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    DDLOG(@"res = %@",responseDict);
                    
                    artistStoreCount = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"totalStore"]];
                    if ([artistStoreCount isKindOfClass:[NSNull class]]&&[artistStoreCount isEqualToString:@"<null>"]) {
                        artistStoreCount = @"0";
                    }
//                    favLabel.text = [NSString stringWithFormat:@"%@次关注",artistStoreCount];
                    scanLabel.text=[NSString stringWithFormat:@"%@次关注",artistStoreCount];
                    
                    [XDTools showTips:@"取消关注成功" toView:self.contentView];
                    
                }else{
                    [XDTools showTips:@"取消关注失败 " toView:self.contentView];
                }
            }
        }];
        
        [request setFailedBlock:^{
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }
}


- (void)getXmlData
{
    //    NSString *id_Str = _idStr;
    //    NSString *type_Str = _typeStr;
//    _idStr = @"3";
//    _typeStr = @"1";
    
    if ([XDTools NetworkReachable]){
        NSString *body = [NSString stringWithFormat:@" <GetArtistInforById xmlns=\"http://tempuri.org/\">"
                          "<artistId>%@</artistId>"
                          "<type>%@</type>"
                          "</GetArtistInforById>",_idStr,_typeStr];
        
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:GETARTISTINFORBYID];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            //[XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            // NSDictionary *tempDic = [XDTools  JSonFromString:responseString];
            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    DDLOG(@"res = %@",responseDict);
                    
                    artistIntroduction = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"artistIntroduction"]];
                    
                    if ([artistIntroduction isEqualToString:@"<null>"]||[artistIntroduction isKindOfClass:[NSNull class]]||artistIntroduction==nil) {
                        artistIntroduction = @"";
                    }
                    DDLOG(@"artistIntroduction = %@",artistIntroduction);

                    artistEducation = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"artistEducation"]];
                    
                    if ([artistEducation isEqualToString:@"<null>"]||[artistEducation isKindOfClass:[NSNull class]]) {
                        artistEducation = @"";
                    }
                    profileLabel.text = artistEducation;
                    
                    artistName = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"artistName"]];
                    if ([artistName isEqualToString:@"<null>"]||[artistName isKindOfClass:[NSNull class]]) {
                        artistName = @"";
                    }
                    artNameLb.text = artistName;
                    
                    artistPortal = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"artistPortal_s"]];
                    if ([artistPortal isEqualToString:@"<null>"]||[artistPortal isKindOfClass:[NSNull class]]) {
                        artistPortal = @"";
                    }
                    
                    NSString * imageUrl = [NSString stringWithFormat:@"%@%@",ImageMainUrl,artistPortal];
                    NSString * urlstring = [imageUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                    //            artImgV.tag = 200;
                    DDLOG(@"url = %@",urlstring);
                    
                    [artImgV setImageWithURL:[NSURL URLWithString:urlstring] placeholderImage:[UIImage imageNamed:@"placehold_image"]];
                    
                    artistScanCount = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"artistScanCount"]];
                    if ([artistScanCount isEqualToString:@"<null>"]||[artistScanCount isKindOfClass:[NSNull class]]) {
                        artistScanCount = @"";
                    }
                    
                    artistStoreCount = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"artistStoreCount"]];
                    if ([artistStoreCount isEqualToString:@"<null>"]||[artistStoreCount isKindOfClass:[NSNull class]]) {
                        artistStoreCount = @"";
                    }
                    
                    artistWorkCount = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"artistWorkCount"]];
                    if ([artistWorkCount isEqualToString:@"<null>"]||[artistWorkCount isKindOfClass:[NSNull class]]) {
                        artistWorkCount = @"0";
                    }
                    scanLabel.text=[NSString stringWithFormat:@"%@次关注",artistStoreCount];
                    
                    NSIndexSet *indexSet1=[[NSIndexSet alloc]initWithIndex:1];
                    [_detailActTableView reloadSections:indexSet1 withRowAnimation:UITableViewRowAnimationAutomatic];
                    
                    NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];
                    [_detailActTableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
//                    [self initWidget];
//                    [_detailActTableView reloadData];
                    
                }else{
//                    [self initWidget];
//                    [XDTools showTips:@"获取数据失败" toView: _detailActTableView];
//                    [_detailActTableView reloadData];
                }
            }
        }];
        
        [request setFailedBlock:^{
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }
    
}

# pragma  mark  ===== GETGALXMLData-----===

- (void)GETGALXMLData{
    
//    _idStr = @"1002";
    if ([XDTools NetworkReachable]){
        NSString *body = [NSString stringWithFormat:@"<GetGalleryInfoById xmlns=\"http://tempuri.org/\">"
                          "<id>%@</id>"
                          "</GetGalleryInfoById>",_idStr];
        __weak ASIFormDataRequest *request = [XDTools postRequestWithDict:body API:GetGalleryInfoById];
        [request setCompletionBlock:^{
            [XDTools hideProgress:self.contentView];
            //[XDTools hideProgress:self.contentView];
            NSString *responseString = [request responseString];
            // NSDictionary *tempDic = [XDTools  JSonFromString:responseString];
            DDLOG(@"responseString:%@", responseString);
            
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            int statusCode = [request responseStatusCode];
            NSString *soapAction = [[request requestHeaders] objectForKey:@"SOAPAction"];
            
            NSArray *arraySOAP =[soapAction componentsSeparatedByString:@"/"];
            int count = [arraySOAP count] - 1;
            NSString *methodName = [arraySOAP objectAtIndex:count];
            
            // Use when fetching text data
            NSString *result = nil;
            if (statusCode == 200) {
                //表示正常请求
                result = [SoapXmlParseHelper SoapMessageResultXml:responseString ServiceMethodName:methodName];
                NSDictionary  *responseDict = [XDTools JSonFromString:result];
                if ([[responseDict objectForKey:@"code"] intValue]==0){
                    DDLOG(@"res = %@",responseDict);
                    responseDict = [responseDict objectForKey:@"_Gallery"];
                    
                    artistIntroduction = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"brief"]];
                    if ([artistIntroduction isEqualToString:@"<null>"]||[artistIntroduction isKindOfClass:[NSNull class]]||artistIntroduction==nil) {
                        artistIntroduction = @"";
                    }
                    DDLOG(@"hualang  aartistIntroduction %@",artistIntroduction);
                    contLabel.text = artistIntroduction;

                    artistEducation = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"city"]];
                  
                    if ([artistEducation isEqualToString:@"<null>"]||[artistEducation isKindOfClass:[NSNull class]]||artistEducation==nil) {
                        artistEducation = @"";
                    }
                      profileLabel.text = artistEducation;
                    
                    artistName = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"name"]];
                    
                    if ([artistName isEqualToString:@"<null>"]||[artistName isKindOfClass:[NSNull class]]||artistName==nil) {
                        artistName = @"";
                    }
                    artNameLb.text = artistName;
                    
                    artistPortal = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"logoUrl"]];
                    
                    if ([artistPortal isEqualToString:@"<null>"]||[artistPortal isKindOfClass:[NSNull class]]||artistPortal==nil) {
                        artistPortal = @"";
                    }
                    
                    NSString * imageUrl = [NSString stringWithFormat:@"%@%@",ImageMainUrl,artistPortal];
                    NSString * urlstring = [imageUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                    //            artImgV.tag = 200;
                    DDLOG(@"url = %@",urlstring);
                    
                    [artImgV setImageWithURL:[NSURL URLWithString:urlstring] placeholderImage:[UIImage imageNamed:@"placehold_image"]];
                    
                    artistStoreCount = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"openTimes"]];
                    
                    if ([artistStoreCount isEqualToString:@"<null>"]||[artistStoreCount isKindOfClass:[NSNull class]]||artistStoreCount==nil) {
                        artistStoreCount = @"0";
                    }
                    
                    scanLabel.text=[NSString stringWithFormat:@"%@次关注",artistStoreCount];
                    
//                    artistStoreCount = @"10";//[NSString stringWithFormat:@"%@",[responseDict valueForKey:@"artistStoreCount"]];
                    artistWorkCount = [NSString stringWithFormat:@"%@",[responseDict valueForKey:@"workCount"]];
                    
//                    NSIndexSet *indexSet1=[[NSIndexSet alloc]initWithIndex:1];
//                    [_detailActTableView reloadSections:indexSet1 withRowAnimation:UITableViewRowAnimationNone];
////
//                    NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];
//                    [_detailActTableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];

//                    [self initWidget];
                    [_detailActTableView reloadData];

                }
            }
        }];
        
        [request setFailedBlock:^{
            [XDTools hideProgress:self.contentView];
        }];
        
        [request startAsynchronous];
        [XDTools showProgress:self.contentView];
    }else{
        [XDTools showTips:brokenNetwork toView:self.contentView];
    }
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
